<?php

namespace Logic;


use Config\mysql;

class WishesLogic
{
    public function saveWishes($uid, $content)
    {
        $create_time = date('Y-m-d H:i:s');
        try {
            $sql = "INSERT INTO `tbWishLog` ( `uid`,`wish_content`,`create_time`) values(:uid,:content,:creatTime)";
            $dbLink = mysql::mysql();
            $st = $dbLink->prepare($sql);
            $row = $st->execute([':uid' => $uid, ':content' => $content, ':creatTime' => $create_time]);
            if ($row) {
                return ['res' => 0, 'msg' => '入库成功!', 'wish_id' => $dbLink->lastInsertId()];
            }
            throw new \PDOException("failed!");
        } catch (\PDOException $e) {
            return ['res' => -1, 'msg' => '发送失败，请重试!' . $e->getMessage(), []];
        }
    }


    /**
     * 根据ids获取祝福语列表
     * @param $randWishesId
     * @return array
     */
    public static function getWishesList($wishesIds)
    {
        $wishesIds = implode(',', $wishesIds);
        $dbLink = mysql::mysql();
        $st = $dbLink->prepare(
            'SELECT id,uid,wish_content FROM `tbWishLog` WHERE id IN  (' . $wishesIds . ')'
        );
        $st->execute();
        $row = $st->fetchAll(\PDO::FETCH_ASSOC);
        return $row;
    }
}